import time

from selenium import webdriver
from selenium.webdriver.chrome.options import Options  # 用于设置谷歌浏览器
from selenium.webdriver.chrome.service import Service  # 用于管理驱动
from selenium.webdriver.common.by import By


# 创建设置浏览器对象
def open_browser():
    o_llq = Options()
    o_llq.add_argument('--no-sandbox')
    o_llq.add_experimental_option('detach', True)
    llq = webdriver.Chrome(service=Service(r'D:\software\chromedriver-win64\chromedriver.exe'), options=o_llq)
    return llq


llq = open_browser()
llq.get('https://baike.baidu.com/item/%e5%8c%97%e4%ba%ac%e5%b8%82/126069')
llq.implicitly_wait(10)

# 获取元素文本内容
text = llq.find_element(By.XPATH, '//*[@id="J-lemma-main-wrapper"]/div[2]/div/div[1]/div/div[2]/div[1]/span[1]').text
print(text)

# 判断内容是否可见，在页面中可以见到的元素返回True，看不见的返回False
is_view = llq.find_element(By.XPATH, '//*[@id="J-lemma-main-wrapper"]/div[2]/div/div[1]/div/div[2]/div[1]/span[1]').is_displayed()
print(is_view)

